/*
 * 文件名：DeletePlazaServiceImpl.java
 * 版权：Copyright by www.tiansu-china.com/
 * 描述：
 * 修改人：congriran
 * 修改时间：2021年2月1日
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
*/

package com.tiansu.reborn.wanda.modules.executor.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tiansu.reborn.wanda.modules.executor.dao.DeletePlazaDao;
import com.tiansu.reborn.wanda.modules.executor.entity.vo.DeletePlazaCondVO;
import com.tiansu.reborn.wanda.modules.executor.service.DeleteDeviceService;
import com.tiansu.reborn.wanda.modules.executor.service.DeletePlazaService;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class DeletePlazaServiceImpl implements DeletePlazaService
{
    @Autowired
    private DeletePlazaDao deletePlazaDao;

    @Autowired
    private DeleteDeviceService deleteDeviceService;

    @Transactional
    @Override
    public String deletePlaza(DeletePlazaCondVO vo)
    {
        int result = deletePlazaDao.checkPlaza(vo);
        if (result != 1)
        {
            log.error("PlazaId does not exist!");
            return "广场数据不存在，请检查！";
        }
        int plazaNum = 0;
        log.debug("Delete plaza begin! PlazaId is: " + vo.getPlazaId());
        plazaNum += deletePlazaDao.deletePaymentRoom(vo.getPlazaId());
        plazaNum += deletePlazaDao.deletePaymentOrganization(vo.getPlazaId());
        plazaNum += deletePlazaDao.deletePaymentAccount(vo.getPlazaId());
        plazaNum += deletePlazaDao.deletePaymentBunk(vo.getPlazaId());
        log.debug("Delete plaza end! PlazaId is: " + vo.getPlazaId() + " A total of "+plazaNum+" plaza data were deleted");
        
        List<Integer> deviceIdList = deletePlazaDao.queryDeviceId(vo.getPlazaId());
        int deviceNum = 0;
        log.debug("Delete device begin!");
        for (Integer deviceId : deviceIdList)
        {
            deviceNum += deleteDeviceService.deleteDevice(deviceId, null);
        }
        log.debug("Delete device end! A total of "+deviceNum+" device data were deleted");
        
        return "一共删除了" + plazaNum + "条广场数据，" + deviceNum + "条设备数据！";
    }

}
